package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.common.config.cache.aop.anntation.Cache;
import com.atguigu.gmall.common.constants.RedisConst;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.to.BaseCategroysTo;
import com.atguigu.gmall.product.dao.BaseCategory1Mapper;

import com.atguigu.gmall.product.dao.BaseCategory2Mapper;
import com.atguigu.gmall.product.dao.BaseCategory3Mapper;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: 业务层
 *
 * @date 2024/9/5 8:19
 */
@Service
public class BaseCategoryServiceImpl implements BaseCategoryService {
    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;
    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;
    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;

    @Cache(CacheKey = RedisConst.CATEGORY_LEVEL_1_KEY)
    //获取一级分类
    @Override
    public List<BaseCategory1> getBaseCategory1(){
        return baseCategory1Mapper.selectList(null);
    }
    @Cache(CacheKey = RedisConst.CATEGORY_LEVEL_2_KEY+":#{#args[0]}")
    //获取二级分类
    @Override
    public List<BaseCategory2> getBaseCategory2(Long category1Id) {
        QueryWrapper<BaseCategory2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category1_id",category1Id);
        List<BaseCategory2> baseCategory2s = baseCategory2Mapper.selectList(queryWrapper);
        return baseCategory2s;
    }
    @Cache(CacheKey = RedisConst.CATEGORY_LEVEL_3_KEY+":#{#args[0]}")
    //获取三级分类
    @Override
    public List<BaseCategory3> getBaseCategory3(Long category2Id) {
        QueryWrapper<BaseCategory3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category2_id",category2Id);
        List<BaseCategory3> baseCategory3s = baseCategory3Mapper.selectList(queryWrapper);
        return baseCategory3s;
    }
    @Cache(CacheKey = RedisConst.CATEGORY_CACHE_KEY)
    @Override
    public List<BaseCategroysTo> getCategorys() {
        return baseCategory1Mapper.getCategorys();

    }

    @Override
    public BaseCategoryView getBaseCategoryView(Long skuId) {
        return baseCategory1Mapper.getBaseCategoryView(skuId);
    }


}
